package com.xmb.wechat.dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;

import com.blankj.utilcode.util.ScreenUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.xmb.wechat.R;
import com.xmb.wechat.bean.GroupTalkBean;
import com.xmb.wechat.bean.WechatContactBean;
import com.xmb.wechat.definterface.GroupWhoSendListener;
import com.xmb.wechat.delegate.ContactChooseDelegate;

import java.util.Objects;

/**
 * @Author lijiangop
 * @CreateTime 2020/3/25 16:47
 */
public class GroupWhoSendDialog extends Dialog {

    public GroupWhoSendDialog(@NonNull Context context, WechatContactBean wechatContactBean, GroupTalkBean groupTalkBean, GroupWhoSendListener listener) {
        super(context, R.style.PopupDialog);
        initView(context, wechatContactBean, groupTalkBean, listener);
    }

    private void initView(Context context, WechatContactBean wechatContactBean, GroupTalkBean groupTalkBean, GroupWhoSendListener listener) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_group_who_send, null, false);
        setContentView(view);

        ContactChooseDelegate contactChooseDelegate = new ContactChooseDelegate(context, view.findViewById(R.id.recyclerView));
        contactChooseDelegate.additem(wechatContactBean);//添加自己
        contactChooseDelegate.addData(groupTalkBean.getGroupMembersList());
        contactChooseDelegate.setOnItemClick(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                WechatContactBean wechatContactBean = (WechatContactBean) contactChooseDelegate.getData().get(position);
                if (listener != null)
                    listener.onChoose(wechatContactBean);
                dismiss();
            }
        });

        WindowManager.LayoutParams lp = Objects.requireNonNull(getWindow()).getAttributes();
        lp.dimAmount = 0.5f;
        lp.width = ScreenUtils.getScreenWidth() * 3 / 4;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    }
}
